package J2ME_LoverTest;


import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;

public class ChoiceHostList extends Form implements ItemCommandListener, CommandListener{
    private LoverTestMIDlet ltm;
    private static Image[] host=new Image[4];
    private ImageItem imageitem[]=new ImageItem[4];
    public int choose=0;
    private Command cmdOk=new Command("Start",Command.OK,1);
    private Command cmdBack=new Command("Back",Command.BACK,1);
   
    
    
    public ChoiceHostList(LoverTestMIDlet ltm) {
		
    	super("Choose Host");
		this.ltm=ltm;
		try{
			
			int temp=0;
			for(int i=0;i<4;i++){
				temp=i+1;
				host[i]=Image.createImage("/host"+temp+".png");
				
		       imageitem[i] = new ImageItem(null,host[i],ImageItem.LAYOUT_LEFT,"host"+temp);
               this.append(imageitem[i]);
               imageitem[i].addCommand(cmdOk);
               imageitem[i].setItemCommandListener(this);
			}
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
	
		this.addCommand(cmdBack);
		this.setCommandListener(this);
		
		
	}



		


		public void commandAction(Command c, Displayable arg1) {
			// TODO Auto-generated method stub
			if(c==cmdBack){
				ltm.changeInterface("WelcomeCanvas");
				
			}
			else if(c==cmdOk){
				
			}
		}



		public void commandAction(Command cmd, Item item) {
			// TODO Auto-generated method stub
			for(int i=0;i<4;i++){
				if(item==imageitem[i]){
			       choose=i;
			       ltm.changeInterface("LoverGameCanvas");
			       break;
				}
				
				
				
			}
			
			
		}
	

}
